using System;
using FreeDraw;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Voodoo.Utils;

public class DrawingTutorial : MonoBehaviour
{
	private Animator m_Animator;

	private const string c_HasDrawingTutorialBeenDisplayedKey = "HasDrawingTutorialBeenDisplayedKey";

	[SerializeField]
	private TextMeshProUGUI m_SkipText;

	[SerializeField]
	private Image m_BackgroundImage;

	private DelayAction hideTutorialDelayed;

	public bool HasDrawingTutorialBeenDisplayed
	{
		get
		{
			return NintendoPlayerPrefs.GetInt("HasDrawingTutorialBeenDisplayedKey") != 0;
		}
		set
		{
			NintendoPlayerPrefs.SetInt("HasDrawingTutorialBeenDisplayedKey", value ? 1 : 0);
		}
	}

	private void Awake()
	{
		m_Animator = GetComponentInChildren<Animator>();
	}

	private void Start()
	{
		if (!HasDrawingTutorialBeenDisplayed)
		{
			Drawable.drawable.ResetCanvas();
			Action action = HideTutorial;
			hideTutorialDelayed = action.Delay(6.5f);
			hideTutorialDelayed.Frequency(0.1f);
			hideTutorialDelayed.Timescale(TimeScale.Scaled);
			hideTutorialDelayed.Begin();
			HasDrawingTutorialBeenDisplayed = true;
			m_Animator.Play("DrawLevelTutorial_anim");
		}
		else
		{
			HideTutorial();
		}
	}

	public void SkipTutorialButtonClicked()
	{
		HideTutorial();
		hideTutorialDelayed?.Cancel();
	}

	private void HideTutorial()
	{
		m_SkipText.gameObject.SetActive(value: false);
		m_BackgroundImage.gameObject.SetActive(value: false);
		m_Animator.gameObject.SetActive(value: false);
	}
}
